<style>
	#fenlei_box{border: 1px solid #3297ff;position: absolute;width:auto;height:250px;overflow-y: auto; z-index:9999;background:#fff;display:none;}
	#fenlei_box li{list-style: none;color:#3297ff;text-align:center;margin-left:-40px;line-height: 32px;cursor: pointer;padding-left:20px;padding-right:20px;}
</style>
                    <form method="post" enctype="multipart/form-data" target="_blank" id="form-order">
                        <div class="table-responsive">
                            <table class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <td style="width: 1px;" class="text-center"><input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);"></td>
    
                                    <td class="text-right">
                                        <a href="javascript:sort('user_id');">ID</a>
                                    </td>
                                    <td class="text-left" width="120">
                                        <a href="javascript:sort('username');">会员昵称</a>
                                    </td>

                                    <td class="text-left">
                                        <a href="javascript:sort('username');">姓名</a>
                                    </td>
                                    <td class="text-left" width="200">
                                        <a href="javascript:sort('province_id');">地址</a>
                                    </td>
                                     <td class="text-left" width="120">
                                        <a href="javascript:sort('environmentalphotos');">环境照片</a>
                                    </td>
                                    <td class="text-left" width="120">
                                        <a href="javascript:sort('doorphoto');">门头</a>
                                    </td>

									<td class="text-center">
                                        <a href="javascript:sort('biaoshi');">标识</a>
                                    </td>
									<td class="text-center">
									    <a href="javascript:sort('biaoshi_xian');">线路</a>
									</td>
									<td class="text-center">
									    <a href="javascript:sort('xsort');">线路排序</a>
									</td>
                                    <td class="text-left">
                                        <a href="javascript:sort('level');">会员等级</a>
                                    </td>
<!--                                    <td class="text-left">
                                        <a href="javascript:sort('total_amount');">累计消费</a>
                                    </td> -->
                                    
                                    <td class="text-left">
                                        <a href="javascript:void(0);">公司/店铺</a>
                                    </td>
<!--                                    <td class="text-left">
                                        <a href="javascript:void(0);">二级下线数</a>
                                    </td> -->
<!--                                    <td class="text-left">
                                        <a href="javascript:void(0);">三级下线数</a>
                                    </td>    -->                                
                                    <td class="text-left">
                                        <a href="javascript:sort('mobile');">手机号码</a>
                                    </td>
									<td class="text-left">
									    <a href="javascript:sort('fenbu_id');">所属区域</a>
									</td>
									<td class="text-left">
                                        <a href="javascript:sort('mobile');">地址</a>
                                    </td>
                                    <td class="text-left" width="60">
                                        <a href="javascript:sort('is_lock');">启用</a>
                                    </td>
                                    <td class="text-left" width="60">
                                        <a href="javascript:sort('is_driver');">配送员</a>
                                    </td>
                                    <td class="text-left" width="60">
                                        <a href="javascript:sort('fast_flag');">快线</a>
                                    </td>
                                    <td class="text-left" width="60">
                                        <a href="javascript:sort('is_lock');">是否业务员</a>
                                    </td>
									<td class="text-left">
									   <a href="javascript:sort('parent_name');" style="width:70px;display:block;">上级推荐人</a>
									</td>
									<td class="text-left">
									   <a href="javascript:sort('xiaxian');" style="width:70px;display:block;">下线数</a>
									</td>
                                    <td class="text-left">
                                        <a href="javascript:sort('pay_points');">积分</a>
                                    </td>
									<td class="text-left">
									   <a href="javascript:sort('total_amount');">累计消费</a>
									</td>
                                    <td class="text-left">
                                        <a href="javascript:sort('reg_time');">注册日期</a>
                                    </td>
                                    <td class="text-center" width="60">操作</td>
                                </tr>
                                </thead>
                                <tbody>
                                <volist name="userList" id="list">
                                    <tr>
                                        <td class="text-center">
                                            <input type="checkbox" name="selected[]" value="{$list['user_id']}">
                                            <input type="hidden" name="shipping_code[]" value="flat.flat">
                                        </td>
                                        <td class="text-right">{$list.user_id}</td>
                                        <td class="text-left">{$list.nick_name}</td>
										<td class="text-left">{$list.nickname}<if condition='$list.first_order_amount neq 0'> <span style="color:red;">首单金额：{$list.first_order_amount}</span></if></td>
										<td class="text-left" style="font-">
										    
										     <span onmouseover="layer.tips('{$list.province}{$list.city}{$list.disti}{$list.street}',this,{tips: [1, '#000']});" onmouseout="layer.closeAll();">地址</span>
										
										</td>
										<td class="text-left"><img src="{$list.environmentalphotos}" height="50" style="cursor: pointer;" onmouseover="layer.tips('<img src={$list.environmentalphotos} width=180>',this,{tips: [1, '#EAF8FF']});" onmouseout="layer.closeAll();"></td>
										<td class="text-left"><img src="{$list.doorphoto}" height="50" style="cursor: pointer;" onmouseover="layer.tips('<img src={$list.doorphoto} width=180>',this,{tips: [1, '#EAF8FF']});" onmouseout="layer.closeAll();"></td>
										<td class="text-center">
											<input type="text" onchange="updateSort('users','user_id','{$list.user_id}','biaoshi',this)" maxlength="10" value="{$list.biaoshi}" class="input-sm" style="width: 80px;text-align: center;">
											</td>
										<td class="text-center">
											<input type="text" onchange="updateSort('users','user_id','{$list.user_id}','biaoshi_xian',this)" maxlength="10" value="{$list.biaoshi_xian}" class="input-sm" style="width: 80px;text-align: center;"> 
											</td>
											<td class="text-center">
											<input type="text" onchange="updateSort('users','user_id','{$list.user_id}','xsort',this)" maxlength="10" value="{$list.xsort}" class="input-sm" style="width: 80px;text-align: center;">
											</td>
                                         <td class="text-left">{$level[$list[level]]}</td> 
                                        <!-- <td class="text-left">{$list.total_amount}</td> -->
										<td class="text-left"><input type="text" onchange="updateSort('users','user_id','{$list.user_id}','company',this)" value="{$list.company}" class="input-sm" style="width: 120px;text-align: center;"></td>
                                        <!-- <td class="text-left">{$first_leader[$list[user_id]]['count']|default="0"}</td> -->
                                        <!-- <td class="text-left">{$second_leader[$list[user_id]]['count']|default="0"}</td>
                                        <td class="text-left">{$third_leader[$list[user_id]]['count']|default="0"}</td> -->
                                        <td class="text-left">{$list.mobile}
										<!--<input type="text" onchange="updateSort('users','user_id','{$list.user_id}','mobile',this)" maxlength="12" value="{$list.mobile}" class="input-sm" style="width: 100px;text-align: center;">-->
<!--                                            <if condition="($list['mobile_validated'] eq 0) AND ($list['mobile'])">
                                                (未验证)
                                            </if> -->
                                        </td>
										<!--区域设置-->
										<td class="text-left">
										<?php
										if(session('fenbu_id')==0){
										?>
										<select onchange="updateSort('users','user_id',{$list.user_id},'fenbu_id',this)" class="input-sm">
											<?php
												foreach($fenbu_list as $v){
													if($list['fenbu_id']==$v['fenbu_id']){
														echo '<option value="'.$v['fenbu_id'].'" selected="selected">'.$v['fenbu_name'].'</option>';
													}else{
														echo '<option value="'.$v['fenbu_id'].'">'.$v['fenbu_name'].'</option>';
													}
												}
											?>
										</select>
										<?php
										}else{
											foreach($fenbu_list as $v){
												if($list['fenbu_id']==$v['fenbu_id']){
													echo $v['fenbu_name'];
												}
											}
										}
										?>
										</td>
										<td class="text-left">
										<input type="text" onchange="updateSort('users','user_id','{$list.user_id}','company_address',this)"  value="{$list.company_address}" class="input-sm" style="width: 200px;text-align: center;">
										</td>
                                        <td class="text-left"><img width="20" height="20" src="__PUBLIC__/images/<if condition='$list[is_lock] eq 0'>yes.png<else />cancel.png</if>" onclick="changeTableVal_shadow('users','user_id','{$list.user_id}','is_lock',this)"/><!-- {$list.user_money} --></td>

                                        <td class="text-left"><img width="20" height="20" src="__PUBLIC__/images/<if condition='$list[is_driver] eq 1'>yes.png<else />cancel.png</if>" onclick="changeTableVal('users','user_id','{$list.user_id}','is_driver',this)"/></td>
                                        <td><img width="20" height="20" src="__PUBLIC__/images/<if condition='$list[fast_flag] eq 1'>yes.png<else />cancel.png</if>" onclick="changeTableVal('users','user_id','{$list.user_id}','fast_flag',this)"/></td>

                                        <td class="text-left">
                                            <img width="20" height="20" src="__PUBLIC__/images/<if condition='$list[salesman] eq 1'>yes.png<else />cancel.png</if>" onclick="changeTableVal_shadow_two('users','user_id','{$list.user_id}','salesman',this)"/>
                                        </td>
                                        <td class="text-left" style="position: relative">
											<input type="text" id="quyu" value="{$list.parent_name}" class="input-sm" style="width:120px;text-align: center;border:1px #00a65a dashed;" oninput="quyu_sousuo($(this))" placeholder="公司/店铺/电话" autocomplete="off">
											<ul id="fenlei_box" rel="{$list.user_id}" style=""></ul>
                                        </td>
										<td class="text-left" style="color: red;cursor: pointer;" title="点击查看"> {$list.xiaxian}
										<i class="fa fa-eye" style="color: green;" id="chakan" rel="{$list.user_id}">查看</i>
										<td class="text-center" style="color:green;">{$list.pay_points}</td>
                                        <td class="text-center" style="color: red;"><?php
								$gouwu=$list[total_amount]>0 ? '是':'否';
								 if(session('role_id')==1){
									echo $list[total_amount];
								 }else{
									 echo $gouwu;
								 }
								 ?></td>
                                        <td class="text-left">{$list.reg_time|date='Y-m-d H:i',###}</td>
                                        <td class="text-right">
                                            <a href="{:U('Admin/user/detail',array('id'=>$list['user_id']))}" data-toggle="tooltip" title="" class="btn btn-info" data-original-title="查看详情"><i class="fa fa-eye"></i></a>
                                            <a href="{:U('Admin/user/address',array('id'=>$list['user_id']))}" data-toggle="tooltip" title="" class="btn btn-info" data-original-title="收货地址"><i class="fa fa-home"></i></a>
                                            <!--<a href="{:U('Admin/order/index',array('user_id'=>$list['user_id']))}" data-toggle="tooltip" title="" class="btn btn-info" data-original-title="订单查看"><i class="fa fa-shopping-cart"></i></a>-->
                                            <a href="{:U('Admin/user/account_log',array('id'=>$list['user_id']))}" data-toggle="tooltip" title="" class="btn btn-info" data-original-title="账户"><i class="glyphicon glyphicon-yen"></i></a>
                                             <a href="{:U('Admin/user/delete',array('id'=>$list['user_id']))}" id="button-delete6" data-toggle="tooltip" title="" class="btn btn-danger" data-original-title="删除"><i class="fa fa-trash-o"></i></a> 
                                             <a href="#" onclick="addcustom({$list['user_id']})" id="addcustom" data-toggle="tooltip" title="加入公海池" class="btn btn-danger" data-original-title="加入公海池"><i class="fa fa-users"></i></a>
                                             <a href="#" onclick="addstaff({$list['user_id']})" id="addstaff" data-toggle="tooltip" title="纳入员工" class="btn btn-danger" data-original-title="纳入员工" style="padding-right: 14px;padding-left: 14px;"><i class="fa fa-user"></i></a>
                                        </td>
                                    </tr>
                                </volist>
                                </tbody>
                            </table>
                        </div>
                    </form>
                    <div class="row">
                        <div class="col-sm-3 text-left">
                        </div>
                        <div class="col-sm-6 text-right">{$page}</div>
                    </div>
<script>
	$(".table-responsive #chakan").click(function(){
		var myrel=$(this).attr('rel');
		var myrul='/index.php/Admin/User/xiaxians/user_id/'+myrel;//+myrel;
			layer.open({
			  type: 2,
			  title:'结算明细',
			  shadeClose: true, //点击遮罩关闭
			  skin: 'layui-layer-rim', //加上边框
			  area: ['920px', '620px'], //宽高
			  content: myrul
		})
	});
	
	 $("body").on("click", function() {
	 	$('body #fenlei_box').hide(100);
	 });
	
	function quyu_sousuo(obj)
	     {
	         var value = obj.val();
	         $.ajax({
	             url:"/Admin/User/quyu_sousuo?key="+value,
	             success: function(data){
					 if(data!=''){
						obj.parent().find('#fenlei_box').show(100);
						obj.parent().find('#fenlei_box').html(data);
					 }else{
						obj.parent().find('#fenlei_box').hide(100);
					 }
	             }
	         });
	     }

	function addstaff(id){
        var value = id;
        $.ajax({
            url:"/Admin/crm/addstaff?id="+value,
            success: function(data){
            	var obj = JSON.parse(data);  
            	if(obj.code == 200){
					 alert(obj.msg);
				 }else{
					 alert(obj.msg);
				 }
            }
        });
    }	    
	 
	function addcustom(id){
        var value = id;
        $.ajax({
            url:"/Admin/crm/addcustom?id="+value,
            success: function(data){
            	var obj = JSON.parse(data); 
            	if(obj.code == 200){
					 alert(obj.msg);
				 }else{
					 alert(obj.msg);
				 }
            }
        });
     }
	
	 $("body").on("click", function() {
	 	$('body #fenlei_box').hide(100);
	 });
	
	$("body #fenlei_box").on("click","li", function() {
			var ids=$(this).attr('rev');
			var id=$(this).parent().attr('rel');
			ids=ids.split(',');
			var parent_id=ids[0];

		$.post("/Admin/User/quyu_edit",
		  {
		    id:id,
		    parent_id:parent_id
		  },
		  function(data,status){
			  layer.msg('推荐人设置成功！',{icon:6,time:1000});
		    $('body #fenlei_box').hide(100);
		  });
			
	});
// 修改指定表的指定字段值
function changeTableVal_shadow(table,id_name,id_value,field,obj)
{
		var src = "";
		console.log($(obj).attr('src').indexOf("cancel.png"))
		 if($(obj).attr('src').indexOf("cancel.png") > 0 )
		 {          
				src = '/Public/images/yes.png';
				var value = 0;
				
		 }else{
				src = '/Public/images/cancel.png';
				var value = 1;
		 }
		 
		$.ajax({
				url:"/index.php?m=Admin&c=Index&a=changeTableVal&table="+table+"&id_name="+id_name+"&id_value="+id_value+"&field="+field+'&value='+value,			
				success: function(data){
				    
					$(obj).attr('src',src);
				}
		});		
}
// 修改指定表的指定字段值
function changeTableVal_shadow_two(table,id_name,id_value,field,obj)
{
		var src = "";
		console.log($(obj).attr('src').indexOf("cancel.png"))
		 if($(obj).attr('src').indexOf("cancel.png") > 0 )
		 {          
				src = '/Public/images/yes.png';
				var value = 1;
				
		 }else{
				src = '/Public/images/cancel.png';
				var value = 2;
		 }
		 
		$.ajax({
				url:"/index.php?m=Admin&c=Index&a=changeTableVal&table="+table+"&id_name="+id_name+"&id_value="+id_value+"&field="+field+'&value='+value,			
				success: function(data){
				    
					$(obj).attr('src',src);
				}
		});		
}
    $(".pagination  a").click(function(){
        var page = $(this).data('p');
        var number = $(this).data('n');
        ajax_get_table('search-form2',page,number);
    });

    $(".page_num").change(function (){
        var number = $(this).val();
        ajax_get_table('search-form2',1,number);
    })

    //批量删除
    function datadel() {
        //获取选中的文章
        layer.confirm('确认要删除吗？',function(index){
            var inputs = $('input:checked');
            var ids ="";
            $.each(inputs,function (k,v) {
                if (v.value != ""){
                    ids += "," + v.value;
                }
            });
            $.ajax({
                type: 'GET',
                data:{
                    id:ids
                },
                url:"{:U('Admin/user/batch_delete')}",
                dataType: 'json',
                success: function(data){
                    if (data.status>0){
                        layer.msg(data.msg,{icon:1,time:1000});
                        document.location.reload();
                    }else{
                        layer.msg(data.msg,{icon:6,time:1000});
                    }

                }
            });
        } ,function(index){
            layer.close(index);
            return false;// 取消
        })
    }
</script>